package com.yanqu.road.dataHelper.del.mgr;

import com.yanqu.road.dataHelper.manager.BaseMgr;
import com.yanqu.road.utils.MyProperties;
import com.yanqu.road.utils.string.StringUtils;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class CrossDelMgr extends BaseMgr {

    private static List<Long> crossIdList = new ArrayList<>();

    private static Map<String, List<String>> tableMap = new ConcurrentHashMap<>();

    private static MyProperties props;

    public static boolean init(String dirPath) {
        String path = dirPath + "config" + File.separator;
        String name = "del.properties";
        props = new MyProperties(path + name);
        String dbCrossStr = props.getProperty("db_cross_union");
        if(!StringUtils.isNullOrEmpty(dbCrossStr)){
            List<String> tmpList = StringUtils.stringToStringList(dbCrossStr,"&");
            crossIdList = StringUtils.stringToLongList(tmpList.get(0),";");
            List<String> infoStrList = StringUtils.stringToStringList(tmpList.get(1),"\\|");
            for(String infoStr : infoStrList){
                List<String> infoList = StringUtils.stringToStringList(infoStr,";");
                tableMap.put(infoList.get(0),infoList);
            }
        }
        return true;
    }

    public static Map<String, List<String>> getTableMap() {
        return tableMap;
    }

    public static List<Long> getCrossIdList() {
        return crossIdList;
    }
}
